package com.wanyang.controller;

import com.wanyang.bo.MemberBO;
import com.wanyang.dto.PageDTO;
import com.wanyang.service.PostService;
import com.wanyang.service.UserContext;
import com.wanyang.vo.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="我的-帖子相关")
@RestController
@RequestMapping("mine")
public class MyPostController {
    @Autowired
    private PostService postService;

    @ApiOperation(value = "最近浏览记录")
    @GetMapping("browseList")
    public ApiResult browseList(PageDTO pageDTO) {
        MemberBO memberBO = UserContext.get();
        return ApiResult.success(postService.queryLastBrowse(memberBO.getId(), pageDTO), null);
    }

    @ApiOperation(value = "删除浏览记录")
    @PostMapping("delBrowse")
    public ApiResult delBrowse(@RequestBody List<Integer> postIds) {
        postService.delBrowse(postIds);
        return ApiResult.success();
    }

    @ApiOperation(value = "收藏记录")
    @GetMapping("collectList")
    public ApiResult collectList(PageDTO pageDTO) {
        MemberBO memberBO = UserContext.get();
        return ApiResult.success(postService.queryCollect(memberBO.getId(), pageDTO), null);
    }

    @ApiOperation(value = "草稿箱")
    @GetMapping("draftList")
    public ApiResult draftList(PageDTO pageDTO) {
        MemberBO memberBO = UserContext.get();
        return ApiResult.success(postService.queryDraft(memberBO.getId(), pageDTO), null);
    }

}
